package com.yingdong.sceneserver.inner.message;

import io.netty.buffer.ByteBuf;
import io.netty.buffer.ByteBufAllocator;

public class RecvGameMessage extends Message {

	private int opcode;

	// ---------------代码展开---------------
	public final int getOpcode() {
		return opcode;
	}

	public final double readDouble() {
		return buffer.readDouble();
	}

	// public final long readLong() {
	// return buffer.readLong();
	// }

	public final float readFloat() {
		return buffer.readFloat();
	}

	public final int readInt() {
		return buffer.readInt();
	}

	public final short readShort() {
		return buffer.readShort();
	}

	public final byte readByte() {
		return buffer.readByte();
	}


	public final long readLong() {
		return buffer.readLong();
	}

	public final String readString() {
		return readString(buffer);
	}

	// ------------------------------------

	public RecvGameMessage(int opcode) {
		this.opcode = opcode;

		buffer = ByteBufAllocator.DEFAULT.buffer(INIT_SIZE);
		buffer.writeInt(opcode);
	}

	public RecvGameMessage(int opcode, ByteBuf buffer) {
		this.opcode = opcode;
		this.buffer = buffer;

	}

	// public byte[] readBytes() {
	// byte[] b = new byte[buffer.readableBytes()];
	// buffer.readBytes(b);
	// return b;
	// }

	public byte[] readBytes(int length) {
		byte[] b = new byte[length];
		buffer.readBytes(b, 0, length);
		return b;
	}
}
